using System;
using System.Collections.Generic;
using System.Text;

namespace Feathertail.Lua
{
    public class LuaFuncDescriptor
    {
        private String FunctionName;
        private String FunctionDoc;
        private Dictionary<string, string> FunctionParameters;
        private String FunctionDocString;

        public LuaFuncDescriptor(String strFuncName, String strFuncDoc, Dictionary<string, string> Params)
        {
            FunctionName = strFuncName;
            FunctionDoc = strFuncDoc;
            FunctionParameters = Params;

            String strFuncHeader = strFuncName + "(%params%) - " + strFuncDoc;
            String strFuncBody = Environment.NewLine + Environment.NewLine;
            String strFuncParams = "";

            Boolean bFirst = true;

            foreach( KeyValuePair<string, string> kvp in Params )
            {
                if (!bFirst)
                {
                    strFuncParams += ", ";
                }

                strFuncParams += kvp.Key;
                strFuncBody += "\t" + kvp.Key + "\t\t" + kvp.Value + "\n";

                bFirst = false;
            }

            strFuncBody = strFuncBody.Substring(0, strFuncBody.Length - 1);
            if (bFirst)
                strFuncBody = strFuncBody.Substring(0, strFuncBody.Length - 1);

            FunctionDocString = strFuncHeader.Replace("%params%", strFuncParams) + strFuncBody;
        }

        public String getFuncName()
        {
            return FunctionName;
        }

        public String getFuncDoc()
        {
            return FunctionDoc;
        }

        public Dictionary<string, string> getFuncParams()
        {
            return FunctionParameters;
        }

        public String getFuncHeader()
        {
            if (FunctionDocString.IndexOf("\n") == -1)
                return FunctionDocString;

            return FunctionDocString.Substring(0, FunctionDocString.IndexOf("\n"));
        }

        public String getFuncFullDoc()
        {
            return FunctionDocString;
        }
    }

}
